<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找出数组里最大的素数</title>
</head>

<body>
  <script>
    var arr = [2, 3, 4, 5, 6, 7, 8, 9, 49, 10, 11, 12, 13, 14, 15, 16, 17, 18, 121]
    // 假设 max 为最大值
    var max = arr[0]
    // 遍历数组
    for (let i = 1; i < arr.length; i++) {
      var falg = true
      // 质数从2开始
      for (let j = 2; j < arr[i]; j++) {
        // 余它本身得0的数不是质数
        if (arr[i] % j == 0) {
          falg = false
        }
      }
      // 为 true 的都是质数
      if (falg == true) {
        console.log(arr[i])
        if (arr[i] > max) {
          max = arr[i]
        }
      }
    }
    console.log('最大的素数为：' + max)
  </script>
</body>

</html>